package com.xt.back.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xt.back.constant.ResultDTO;
import com.xt.back.dto.CourseMappingDto;
import com.xt.back.dto.RewardMappingDto;
import com.xt.back.entity.CourseMapping;
import com.xt.back.entity.RewardMapping;
import com.xt.back.service.IRewardMappingService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 用户奖励关联表 前端控制器
 * </p>
 *
 * @author leotong
 * @since 2022-04-03
 */
@CrossOrigin
@RestController
@RequestMapping("/back/rewardMapping")
@AllArgsConstructor
public class RewardMappingController {

    private final IRewardMappingService rewardMappingService;

    @PostMapping("/add")
    public ResultDTO<Boolean> addRewardMapping(@RequestBody RewardMapping rewardMapping){
        return ResultDTO.success(rewardMappingService.save(rewardMapping));
    }

    @GetMapping("/remove")
    public ResultDTO<Boolean> deleteRewardMapping(int id){
        return ResultDTO.success(rewardMappingService.removeById(id));
    }

    @PostMapping("/update")
    public ResultDTO<Boolean> updateRewardMapping(@RequestBody RewardMapping rewardMapping){
        return ResultDTO.success(rewardMappingService.updateById(rewardMapping));
    }

    @PostMapping("/getRewardMappingByPage")
    public ResultDTO<Page<RewardMappingDto>> getRewardMappingByPage(@RequestBody RewardMapping rewardMapping){
        return ResultDTO.success(rewardMappingService.getRewardMappingByPage(rewardMapping));
    }

    @GetMapping("/getAllRewardMapping")
    public ResultDTO<List<RewardMappingDto>> getAllRewardMapping() {
        return ResultDTO.success(rewardMappingService.getAllRewardMapping());
    }
}
